package com.gopay.scheduler.dao.qulifications.impl;

import com.gopay.common.base.dao.impl.BaseReadDAOImpl;
import com.gopay.common.order.dao.CommonQueryDAO;
import com.gopay.common.util.LogUtil;
import com.gopay.scheduler.dao.qulifications.OverQualificationsInfoReadDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.*;

/**
 * CLASSNAME:OverQualificaitonsInfoReadDaoImpl
 * Description:过期资质统计类，包含统计营业执照过期和法人证件过期方法
 * DATE:2017/5/4/004
 * AUTHER:PANSHICHAO
 * www.gopay.com.cn Inc.All rights reserved.
 */
@Component("overQualificationsInfoReadDao")
public class OverQualificaitonsInfoReadDaoImpl extends BaseReadDAOImpl<Object[],String> implements OverQualificationsInfoReadDao{
    @Autowired
    private CommonQueryDAO commonQueryDAO;
    @Override
    public List<Object[]> getAllBusinessTermOverQualificationsInfo(Date nowDate,Date endDate) {
        String sql ="SELECT CUST_ID，CORP_NAME,EMAIL,BUSINESS_TERM,IS_MERCHANT FROM\n" +
                "CUST_CORP_INFO\n"+
                "where BUSINESS_TERM >= trunc(:startDate) and BUSINESS_TERM < trunc(:endDate) and IS_REAL_NAME_CERTIFY = '1' order by BUSINESS_TERM";

        Map<String,Object> param = new HashMap<String,Object>();
        param.put("startDate",nowDate);
        param.put("endDate",endDate);
        List<Object[]> resultList = super.findBySql(sql,param);
        if(resultList == null || resultList.size() == 0){
            return null;
        }else{
            return resultList;
        }
    }

    @Override
    public List<Object[]> getAllLegalPersonCertTermOverQualificationsInfo(Date nowDate,Date endDate) {
        String sql ="SELECT CUST_ID，CORP_NAME,EMAIL,LEGAL_PERSON_CERT_TERM,IS_MERCHANT FROM\n" +
                "CUST_CORP_INFO\n"+
                "where LEGAL_PERSON_CERT_TERM >= trunc(:startDate) and LEGAL_PERSON_CERT_TERM <trunc(:endDate) and IS_REAL_NAME_CERTIFY = '1' order by LEGAL_PERSON_CERT_TERM";

        Map<String,Object> param = new HashMap<String,Object>();
        param.put("startDate",nowDate);
        param.put("endDate",endDate);
        List<Object[]> resultList = super.findBySql(sql,param);
        if(resultList == null || resultList.size() == 0){
            return null;
        }else{
            return resultList;
        }
    }

    @Override
    public List<Object[]> getAllQualificationsInfo(Date nowDate, Date endDate) {
        String sql ="SELECT CUST_ID,CORP_NAME,EMAIL,LEGAL_PERSON_CERT_TERM,BUSINESS_TERM FROM\n" +
                "CUST_CORP_INFO\n"+
                "where ((LEGAL_PERSON_CERT_TERM >= trunc(:startDate) and LEGAL_PERSON_CERT_TERM <trunc(:endDate)) or (BUSINESS_TERM >= trunc(:startDate) and BUSINESS_TERM < trunc(:endDate))) and IS_REAL_NAME_CERTIFY = '1' order by LEGAL_PERSON_CERT_TERM";

        Map<String,Object> param = new HashMap<String,Object>();
        param.put("startDate",nowDate);
        param.put("endDate",endDate);
        List<Object[]> resultList = super.findBySql(sql,param);
        if(resultList == null || resultList.size() == 0){
            return null;
        }else{
            return resultList;
        }
    }

    @Override
    public List<Object[]> getAllHasOverQualificationInfo(Date nowDate) {
        String sql ="SELECT CUST_ID，CORP_NAME,EMAIL,LEGAL_PERSON_CERT_TERM,BUSINESS_TERM FROM\n" +
                "CUST_CORP_INFO\n"+
                "where (LEGAL_PERSON_CERT_TERM < trunc(:startDate) or BUSINESS_TERM < trunc(:startDate)) and IS_REAL_NAME_CERTIFY = '1' ";

        Map<String,Object> param = new HashMap<String,Object>();
        param.put("startDate",nowDate);
        List<Object[]> resultList = super.findBySql(sql,param);
        if(resultList == null || resultList.size() == 0){
            return null;
        }else{
            return resultList;
        }
    }

    @Override
    public List<Object[]> showAcctOperatorLogByAcctIdAndLastUpdTime(String acctId) {
        StringBuilder sql = new StringBuilder();
        sql.append(" select a.gmt_create, a.lock_type, a.opera_res, a.remark ")
                .append("  from ACPS_ACCT_OPERAT_LOGS a ")
                .append(" where a.acct_id = :acctId ")
                .append(" order by a.gmt_create desc");
        Map<String, Object> param = new HashMap<>(1);
        param.put("acctId", acctId);
        List<Object[]> resultList= commonQueryDAO.findBySql( sql.toString() , param);
        if(resultList.isEmpty()){
            return null;
        }else{
            return resultList;
        }
    }
}
